package com.example.friend.controller;


import com.example.common.core.constants.HttpConstants;
import com.example.common.core.domain.R;
import com.example.friend.domain.exam.dto.ExamDTO;
import com.example.friend.service.IUserExamService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/user/exam")
@Slf4j
public class UserExamController {
    @Autowired
    private IUserExamService examService;

    @PostMapping("/enter")
    public R<Void> enter(@RequestHeader(HttpConstants.AUTHENTICATION) String token,
                         @RequestBody ExamDTO examDTO) {
        log.info("/user/exam/enter:token{},examDto{}", token, examDTO);
        int enter = examService.enter(token, examDTO.getExamId());
        return enter == 1 ? R.ok() : R.fail();
    }
}
